package oj;

import java.util.Scanner;

/**
 * @author ：冯涛滔
 * @date ：Created in 2020-4-25 15:23
 * @description：
 * @modified By：
 * @version:
 */
public class Oj7 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNextInt()){
            int size = in.nextInt();
            int maxTime = 0;
            Student[] list = new Student[size];
            int time = 0;//老师花掉的时间
            for (int i = 0; i < size; i++) {
                int j = i;
                list[i] = new Student(in.nextInt(),in.nextInt());
                while(j>0){
                    if(list[j].finishTime>list[j-1].finishTime){
                        Student s = list[j-1];
                        list[j-1] = list[j];
                        list[j] = s;
                        j--;
                    }else {
                        break;
                    }
                }
            }
            for (int i = 0; i < list.length; i++) {
                int finishTime = time+list[i].time+list[i].finishTime;
                if(finishTime>maxTime){
                    maxTime = finishTime;
                }
                time+=list[i].time;
            }
            System.out.println("Project " + size + ": " + maxTime);
        }
    }
    static class Student{
        int time;
        int finishTime;
        int maxTime;

        public Student(int time, int finishTime) {
            this.time = time;
            this.finishTime = finishTime;
        }
    }
}
